#include "RtTimerLoop.h"

RtTimerLoop::RtTimerLoop(const QString& name) :
	RtLoop(name), period_(1000)
{
}
RtTimerLoop::~RtTimerLoop(void)
{
}
bool RtTimerLoop::arm_()
{
	disarm_();
	if (timer_.start(this,period_)) return RtLoop::arm_();
	else return false;
}

void RtTimerLoop::disarm_()
{
	timer_.stop();
	RtLoop::disarm_();
}
void RtTimerLoop::setPeriod(unsigned int p)
{
	if (p<10) p=10; // minimum 10 ms
	if (period_ != p)
	{
		bool onlineChange = armed_;
		if (onlineChange)
		{
			jobLock();
			disarm_();
		}
		period_ = p;
		if (onlineChange)
		{
			arm_();
			jobUnlock();
		}
		emit propertiesChanged();
	}
}
